package com.design.pattern.strategy;

import java.util.Optional;

/**
 * @author goujian
 * @description: TODO
 * @date 2022/3/13 11:27 下午
 */
public class Context {
    private MakeVehicleStrategy makeVehicleStrategy;
    private UseVehicleStrategy useVehicleStrategy;

    public Context() {
    }

    public Context(MakeVehicleStrategy makeVehicleStrategy) {
        this.makeVehicleStrategy = makeVehicleStrategy;
    }

    public Context(UseVehicleStrategy useVehicleStrategy) {
        this.useVehicleStrategy = useVehicleStrategy;
    }

    public Context(MakeVehicleStrategy makeVehicleStrategy, UseVehicleStrategy useVehicleStrategy) {
        this.makeVehicleStrategy = makeVehicleStrategy;
        this.useVehicleStrategy = useVehicleStrategy;
    }

    /**
     * 具体的业务函数
     */
    public void handler() {
        Optional.ofNullable(makeVehicleStrategy).ifPresent(MakeVehicleStrategy::makeVehicle);
        Optional.ofNullable(useVehicleStrategy).ifPresent(UseVehicleStrategy::useVehicle);
    }
}
